package net.sf.xmlform.springmvcexample.user;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import net.sf.xmlform.data.ResultData;

@RestController
public class UserRestController {
	@Autowired
	private UserStore store;
	@RequestMapping(value="/ruser",method=RequestMethod.POST)
	public User addUser(User user){
		store.getUsers().put(user.getCode(),user);
		return user;
	}
	@RequestMapping(value="/ruser/{code}",method=RequestMethod.GET)
	public User user(@PathVariable("code") String code){
		return (User)store.getUsers().get(code);
	}
	@RequestMapping("/ruser/list")
	public ResultData users(){
		List list=new ArrayList(store.getUsers().values());
		ResultData result=new ResultData();
		result.setData(list);
		return result;
	}
}
